package com.example.studentalarm.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * TimeUtils
 */
public class TimeUtils {

    private final static String TAG = "TimeUtils";

    public final static String PATTERN = "yyyy-MM-dd";

    public final static String CHINA_PATTERN = "yyyy年MM月dd日";

    public final static String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";


    public static Calendar stringToDate(String dateStr, String dateFormat) {
        Calendar calendar = Calendar.getInstance();

        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
        try {
            Date date = formatter.parse(dateStr);
            calendar.setTime(date);
            return calendar;
        } catch (ParseException e) {
            LogUtil.d(e.getMessage());
            return null;
        }
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getDate() {
        Date date = new Date();// 获取当前日期对象
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置格式
        return format.format(date);
    }

    public static String getDate(String formatStr) {
        Date date = new Date();// 获取当前日期对象
        SimpleDateFormat format = new SimpleDateFormat(formatStr);// 设置格式
        return format.format(date);
    }

    public static String getDate(String formatStr, long times) {
        Date date = new Date(times);// 获取当前日期对象
        SimpleDateFormat format = new SimpleDateFormat(formatStr);// 设置格式
        return format.format(date);
    }


}